<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\helpers\StringHelper;
use backend\helpers\ActionButton;
use backend\models\News;

/* @var $this yii\web\View */
/* @var $model backend\models\News */

$this->title = StringHelper::truncate($model->content, 50);
$this->params['breadcrumbs'][] = ['label' => 'Новости', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container news-view">

    <h1 class="main-title"><?= Html::encode($this->title) ?></h1>

    <p>
        <?= ActionButton::update($model->id, 'updateNews') ?>
        <?= ActionButton::delete($model->id, 'Вы точно хотите удалить новость?', 'deleteNews') ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'options' => ['class' => 'table table-striped detail-view'],
        'attributes' => [
            'id',
            [
                'label' => 'Информационный канал',
                'attribute' => 'infoChanel.title',
            ],
            'date_public:date',
            'content:ntext',
            [
                'attribute'=>'prev_img',
                'format' => 'raw',
                'value' => function($model) {
                    return Html::img(
                        'https://storage.yandexcloud.net/' . News::BUCKET_NAME . '/' . $model->prev_img, 
                        [
                            'alt'=>'',
                            'class' => 'img-thumbnail',
                            'style' => 'width:200px;'
                        ]
                    );
                },
            ],
            [
                'attribute'=>'gallery_img',
                'format' => 'raw',
                'value' => function($model) {
                    $gallery = '';
                    if(!empty($model->gallery_img))
                    {
                        foreach(explode(',', $model->gallery_img) as $image)
                        {
                            $gallery .= Html::img(
                                'https://storage.yandexcloud.net/' . News::BUCKET_NAME . '/' . $image, 
                                $options = ['class' => 'img-thumbnail', 'style' => ['width' => '200px']]
                            );
                        }   
                    }

                    return $gallery;
                },
            ]
        ],
    ]) ?>


</div>
